package lec07datastructure.v1;

/**
 * Created by Administrator on 2021/3/29.
 */
public class MyLinkedList {
    static class Node {
        int data;
        Node pre, next;

        public Node(int data) {
            this(data, null, null);
        }

        public Node(int data, Node pre, Node next) {
            this.data = data;
            this.pre = pre;
            this.next = next;
        }
    }

    Node head = null;
    Node tail = null;
    int size = 0;

    void addLast(Node node) {
        if (head == null) {
            head = tail = node;
            ++size;
            return;
        }

        tail.next = node;
        node.pre = tail;
        tail = node;
        ++size;
        return;
    }

    public static void main(String[] args) {
        MyLinkedList list = new MyLinkedList();
        for (int i = 0; i < 10; i++) {
            list.addLast(new Node(i));
        }
        Node first = list.head;
        while (first != null) {
            System.out.print(first.data);
            first = first.next;
        }
        System.out.println();
        Node last = list.tail;
        while (last != null) {
            System.out.print(last.data);
            last = last.pre;
        }
    }
}
